//package cc.magicjson.processor;
//
//import cc.magicjson.manager.ServerManager;
//import cc.magicjson.utils.PortUtils;
//import org.springframework.beans.BeansException;
//import org.springframework.boot.SpringApplication;
//import org.springframework.boot.env.EnvironmentPostProcessor;
//import org.springframework.context.ApplicationContext;
//import org.springframework.context.ApplicationContextAware;
//import org.springframework.context.ConfigurableApplicationContext;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.core.env.ConfigurableEnvironment;
//import org.springframework.core.env.Environment;
//
///**
// * {@link}
// *
// * @author <a href="mailto:it_magicjson@163.com">MagicJson</a>
// * @since 1.0.0
// */
//@Configuration
//public class PortWriteableEnvironmentProcessor implements ApplicationContextAware {
////	@Override
////	public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
////		Integer defaultPort = environment.getProperty("server.port", Integer.class);
////		Integer backPort = environment.getProperty("server.back-port", Integer.class);
////		if (PortUtils.isPortInUse(defaultPort)) {
//////			defaultPort = backPort;
////			// Optional: if switching ports, you might need to restart or reconfigure the app
////			ServerManager.switchToDefaultPort(application.run(), backPort);
////		}
////
////	}
//
//	@Override
//	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
//		Environment environment = applicationContext.getEnvironment();
//		Integer defaultPort = environment.getProperty("server.port", Integer.class);
//		Integer backPort = environment.getProperty("server.back-port", Integer.class);
//		if (PortUtils.isPortInUse(defaultPort)) {
////			defaultPort = backPort;
//			// Optional: if switching ports, you might need to restart or reconfigure the app
////			applicationContext.
//			if(applicationContext instanceof ConfigurableApplicationContext){
//				ConfigurableApplicationContext context = (ConfigurableApplicationContext) applicationContext;
//				ServerManager.switchToDefaultPort(context, backPort);
//			}
//
//		}
//	}
//}
